#ifndef RSA_H
#define RSA_H

#include <QObject>
#include <QString>
#include <QByteArray>
#include <openssl/evp.h>
#include <stdio.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>


class rsa:public QObject
{
    Q_OBJECT
    public:
        EVP_CIPHER_CTX *ctx;

        bool encrypt(const QByteArray origin_data,QByteArray &enc_data, size_t &enc_data_len);
        bool decrypt(const QByteArray enc_data,size_t enc_data_len,QByteArray &dec_data, size_t &dec_data_len);
        
    private:

        int generate_key_files(const char *pub_keyfile, const char *pri_keyfile, const unsigned char *passwd, int passwd_len);
        EVP_PKEY* open_public_key(const char *keyfile);
        EVP_PKEY* open_private_key(const char *keyfile, const unsigned char *passwd);
        int rsa_key_encrypt(EVP_PKEY *key, const unsigned char *orig_data, size_t orig_data_len,unsigned char *enc_data, size_t &enc_data_len);
        int rsa_key_decrypt(EVP_PKEY *key, const unsigned char *enc_data, size_t enc_data_len, unsigned char *dec_data, size_t &dec_data_len);

};

#endif // RSA_H
